import router from '@/router'
import store from '@/store'
// import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import getters from './store/getters'
const whiteList = ['/login', '/404']

router.beforeEach (async(to, from, next) => {
  const token = store.getters.token
 if (token) {
  if(!store.getters.name){
    await store.dispatch('user/getUserInfo')
  }
  // NProgress.start()
   if (to.path === '/login') {
     next('/')
   }else {
     next()
   }
 } else {
   if (whiteList.includes(to.path)) {
     next()
   } else {
     next('/login')
   }
  //  NProgress.done()
 }
})
